package org.code.boot.controller.common;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.code.boot.common.annotation.Log;
import org.code.boot.common.enums.BusinessType;
import org.code.boot.common.utils.poi.ExcelUtil;
import org.code.boot.controller.BaseController;
import org.code.boot.vo.AjaxResult;
import org.code.boot.vo.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.code.boot.domain.common.ComLike;
import org.code.boot.service.common.IComLikeService;

/**
 * 通用点赞Controller
 * 
 * @author ruoyi
 * @date 2023-08-27
 */
@RestController
@RequestMapping("/common/like")
public class ComLikeController extends BaseController
{
    @Autowired
    private IComLikeService bizLikeService;

    /**
     * 查询通用点赞列表
     */
    @PreAuthorize("@ss.hasPermi('common:like:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComLike comLike)
    {
        startPage();
        List<ComLike> list = bizLikeService.selectBizLikeList(comLike);
        return getDataTable(list);
    }

    /**
     * 导出通用点赞列表
     */
    @PreAuthorize("@ss.hasPermi('common:like:export')")
    @Log(title = "通用点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComLike comLike)
    {
        List<ComLike> list = bizLikeService.selectBizLikeList(comLike);
        ExcelUtil<ComLike> util = new ExcelUtil<ComLike>(ComLike.class);
        util.exportExcel(response, list, "通用点赞数据");
    }

    /**
     * 获取通用点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('common:like:query')")
    @GetMapping(value = "/{likeId}")
    public AjaxResult getInfo(@PathVariable("likeId") Long likeId)
    {
        return success(bizLikeService.selectBizLikeByLikeId(likeId));
    }

    /**
     * 新增通用点赞
     */
    @PreAuthorize("@ss.hasPermi('common:like:add')")
    @Log(title = "通用点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComLike comLike)
    {
        return toAjax(bizLikeService.insertBizLike(comLike));
    }

    /**
     * 修改通用点赞
     */
    @PreAuthorize("@ss.hasPermi('common:like:edit')")
    @Log(title = "通用点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComLike comLike)
    {
        return toAjax(bizLikeService.updateBizLike(comLike));
    }

    /**
     * 删除通用点赞
     */
    @PreAuthorize("@ss.hasPermi('common:like:remove')")
    @Log(title = "通用点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{likeIds}")
    public AjaxResult remove(@PathVariable Long[] likeIds)
    {
        return toAjax(bizLikeService.deleteBizLikeByLikeIds(likeIds));
    }

    /**
     * 点赞/取消点赞
     */
    @PostMapping("/toggle/{businessType}/{businessId}")
    public AjaxResult toggleLike(@PathVariable String businessType, @PathVariable Long businessId)
    {
        return bizLikeService.toggleLike(businessType, businessId);
    }

    /**
     * 获取点赞信息
     */
    @GetMapping("/info/{businessType}/{businessId}")
    public AjaxResult getLikeInfo(@PathVariable String businessType, @PathVariable Long businessId)
    {
        return bizLikeService.getLikeInfo(businessType, businessId);
    }
}